package com.wits.media;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * Created by zhengboyuan on 2018-03-12.
 */

public class OsdOverlay {

    public static final int MAX_COUNT = 4;      // 最大个数

    public static final int MIN_FONT_SIZE = 12;     /// 最小字体
    public static final int MAX_FONT_SIZE = 80;     /// 最大字体

    public static final int ANTI_ALIAS_FLAG = 1;    /// 抗锯齿, 字体线条效果会变粗

    public static final int TYPE_TEXT = 0;      /// 静态文本OSD
    public static final int TYPE_DATETIME = 1;  /// 时间OSD
    public static final int TYPE_IMAGE = 2;     /// 图片OSD

    public static class OsdFont
    {
        public int  size;		    /// 字体大小, 取值范围: [12, 80]
        public boolean italic;		/// > 0 表示 斜体
        public boolean bold;		/// >0 表示粗体
        public String  name;	    /// 字体名称, 为空或者null表示默认字体

        public OsdFont()
        {
            this.size = 16;
            this.italic = false;
            this.bold = false;
            this.name = "";
        }
    };

    public int top;		/// 目标位置矩形, 取值应该小于图像分辨率, 否则部分内容不可见
    public int left;
//    int width;
//    int height;

    public OsdFont font = new OsdFont();

    public int color = 0x00FFFFFF;
    public int background;     /// 背景色.
    public int alpha = 255;    /// 透明度, 取值 [0,255], 0 表示完全透明,即不可见
    public boolean transparent = true;    ///

    public int type = TYPE_TEXT;            /// 类型, 可以是 文本,时间,图片

    /// 当类型为时间时, text 表示时间格式, 比如: yy-MM-dd HH:mm:ss, 详细参考 SimpleDateFormat
    public String text = "";

    public int flags;
    public Context context;


    /**
     * 设置日期类型OSD
     * @param pattern   日期模式, @see SimpleDateFormat
     */
    public void setDateTime(String pattern) {
        this.type = TYPE_DATETIME;
        this.text = pattern;
    }

    /**
     * 设置静态文本OSD
     * @param text
     */
    public void setText(String text) {
        this.type = TYPE_TEXT;
        this.text = text;
    }

    /**
     * 设置图片OSD
     * @param context
     * @param id        资源ID
     */
    public void setImage(Context context, int id) {
        this.type = TYPE_IMAGE;
        this.text = context.getResources().getResourceName(id);
        this.context = context;

        int rid = context.getResources().getIdentifier(this.text, null, null);
        Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), rid);
        if (bitmap == null) {
            rid = 0;
        }
    }

    /**
     * 设置图片OSD
     * @param filepath  绝对路径
     */
    public void setImage(String filepath) {
        this.type = TYPE_IMAGE;
        this.text = filepath;
    }


}
